package com.thirtydays.oral.common.config;

import cn.hutool.db.DbUtil;
import cn.hutool.db.SqlConnRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * TODO
 *
 * @author Dell
 * @version 1.0
 * @date 2021/5/15 19:49
 */
@Configuration
public class DBConfig {

    @Value("${spring.datasource.driver-class-name}")
    private String driver;

    @Value("${spring.datasource.url}")
    private String url;

    @Value("${spring.datasource.username}")
    private String username;

    @Value("${spring.datasource.password}")
    private String password;

    @Bean
    public Connection getConnection() {
        Connection connection = null;
        //加载驱动程序
        try {
            Class.forName(driver);
            //获取数据库连接对象
            connection = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        assert connection != null;
        return connection;
    }
}
